package parser;

import java.io.IOException;
import java.io.StringReader;

import javax.mail.MessagingException;
import javax.mail.Part;

import org.ccil.cowan.tagsoup.Parser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Cette classe extrait les mots d'une partie de message en HTML
 *
 */
public class HTMLWordsExtractor implements WordsExtractor
{
	private Part part;
	
	
	public HTMLWordsExtractor(Part part)
	{
		this.part = part;
	}

	@Override
	public void extractWords(WordsHandler wordsHander)
	{
		Parser htmlParser = new Parser();
		htmlParser.setContentHandler(new HTMLHandler(wordsHander));
		try
		{
			String body = (String) part.getContent();
			htmlParser.parse(new InputSource(new StringReader(body)));
		}
		catch (IOException e)
		{
		}
		catch (SAXException e)
		{
		}
		catch (MessagingException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
